//
//  ViewController.m
//  ibeacon客户端
//
//  Created by MyMac on 15/9/11.
//  Copyright (c) 2015年 tongfang. All rights reserved.
//

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <CoreBluetooth/CoreBluetooth.h>
NSString *const UUIDString=@"76B5F6C3-6390-4BBC-B3C9-84AD8C92BCA5";
@interface ViewController ()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLLocationManager*locationManager;
@property(nonatomic,strong)CLBeaconRegion*beaconRegion;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.locationManager=[[CLLocationManager alloc]init];
     self.locationManager.delegate=self;
    if (![CLLocationManager locationServicesEnabled]) {
        return;
    }
    [self.locationManager requestAlwaysAuthorization];
        NSLog(@"经授权的%d",[CLLocationManager authorizationStatus]);
    
    
   // [self.locationManager requestWhenInUseAuthorization];
    //过滤距离,水平移动多少生成一次位置改变信号
    self.locationManager.distanceFilter=50;
    //进度最佳
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    //不移动时自动暂停定位
    //self.locationManager.pausesLocationUpdatesAutomatically=YES;
   
    NSUUID*UUID=[[NSUUID alloc]initWithUUIDString:UUIDString];
    NSString*identifier=[[NSBundle mainBundle]bundleIdentifier];
    self.beaconRegion=[[CLBeaconRegion alloc]initWithProximityUUID:UUID identifier:identifier];
   // 监测CLBeaconRegion
    [self.locationManager startMonitoringForRegion:self.beaconRegion];
   // 测量CLBeaconRegion
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
    //请求CLBeaconRegion的状态
    [self.locationManager requestStateForRegion:self.beaconRegion];
    //开始更新
    [self.locationManager startUpdatingLocation];
    
    
    
}
- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations
{
    NSLog(@"位置改变了");


}
- (void)locationManager:(CLLocationManager *)manager
       didUpdateHeading:(CLHeading *)newHeading
{

    NSLog(@"方向改变了");

}
- (void)locationManager:(CLLocationManager *)manager
      didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{

    NSLog(@"蓝牙信号状态改变");
    


}
- (void)locationManager:(CLLocationManager *)manager
        didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
    NSLog(@"一个新的蓝牙信号");

}
- (void)locationManager:(CLLocationManager *)manager
rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region
              withError:(NSError *)error
{

    NSLog(@"错误%@",error);

}
- (void)locationManager:(CLLocationManager *)manager
         didEnterRegion:(CLRegion *)region
{


    NSLog(@"进入这个CLRegion：%@",region);

}
- (void)locationManager:(CLLocationManager *)manager
          didExitRegion:(CLRegion *)region
{
    NSLog(@"存在CLRegion：%@",region);

}
- (void)locationManager:(CLLocationManager *)manager
monitoringDidFailForRegion:(CLRegion *)region
              withError:(NSError *)error
{

    NSLog(@"监听失败:%@   error:%@",region,error);
}
- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    NSLog(@"位置定位失败:%@",error);

}
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region
{

    NSLog(@"开始监听这个CLRegion：%@",region);


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
